﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace LifeRestartConfigTool
{
    /// <summary>
    /// 文件工具类
    /// </summary>
    public class FileUtil
    {
        /// <summary>
        /// 写入文件
        /// </summary>
        /// <param name="path">目标路径</param>
        /// <param name="str">待写入字符串</param>
        public static void WriteToFile(string path, string str)
        {
            using (StreamWriter sw = new StreamWriter(File.Open(path, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)))
            {
                sw.Write(str);
            }
        }

        /// <summary>
        /// 从文件中读取
        /// </summary>
        /// <param name="path">待读取文件路径</param>
        public static string ReadFromFile(string path)
        {
            using (StreamReader sr = new StreamReader(File.OpenRead(path)))
            {
                return sr.ReadToEnd();
            }
        }
    }
}
